#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;
int N, M, TT;

namespace Dinic{
	const int MAXN = 260000, MAXM = 3e6;
	int qxx[MAXM<<1][3];
	int tt[MAXN], nn, currM[MAXN];
	int N, S, T;
	
	void addE(int a, int b, int c){
		qxx[++nn][0] = b;
		qxx[nn][1] = c;
		qxx[nn][2] = tt[a];
		tt[a] = nn;
	}
	void addEs(int a, int b, int c){
		addE(a, b, c);
		addE(b, a, 0);
	}
	void init(){
		nn = 1;
		for(int i=1; i<=N; i++)
			tt[i] = 0;
		N = S = T = 0;
	}
	queue<int> Q;
	int dis[MAXN];
	bool bfs(){
		for(int i=1; i<=N; i++)
			dis[i] = 1e9;
		dis[S] = 0; currM[S] = tt[S];
		while(!Q.empty())
			Q.pop();
		Q.push(S);
		while(!Q.empty()){
			int x = Q.front(); Q.pop();
			for(int i=tt[x], v, w; i; i=qxx[i][2]){
				v = qxx[i][0], w = qxx[i][1];
				if(w && dis[v] > dis[x] + 1){
					dis[v] = dis[x] + 1;
					currM[v] = tt[v];
					Q.push(v);
					if(v == T)
						return true;
 				}
			}
		}
		return false;
	}
	long long dfs(int x, long long sm){
		if(x == T || sm == 0)
			return sm;
		long long ret = 0;
		for(int i=currM[x], v, w; i; i=qxx[i][2]){
			v = qxx[i][0];
			w = qxx[i][1];
			currM[x] = i;
			if(w && dis[v] == dis[x] + 1){
				long long k = dfs(v, min(1ll*w, sm));
				sm -= k; ret += k;
				qxx[i][1] -= k; qxx[i^1][1] += k;
				if(sm == 0)
					return ret;
			}
		}
		return ret;
	}
	inline long long calcAns(){
		long long ans = 0;
		while(bfs())
			ans += dfs(S, 1e18);
		return ans;
	}
	inline int newN(){
		return ++N;
	}
	inline int newS(){
		return S = ++N;
	}
	inline int newT(){
		return T = ++N;
	}
}

int dis1[510][510], dis2[510][510];
int ID[510][510], S, T;
inline int getLnk(int x){
	if(x <= M)
		return ID[1][x];
	x -= M;
	if(x <= N)
		return ID[x][M];
	x -= N;
	if(x <= M)
		return ID[N][M + 1 - x];
	x -= M;
	return ID[N + 1 - x][1];
}
vector<pair<int, int> > B, W;

int main(){
	freopen("traffic.in", "r", stdin);
	freopen("traffic.out", "w", stdout);
	scanf("%d%d%d", &N, &M, &TT);
	for(int i=1; i<N; i++)
		for(int j=1; j<=M; j++)
			scanf("%d", &dis1[i][j]);
	for(int i=1; i<=N; i++)
		for(int j=1; j<M; j++)
			scanf("%d", &dis2[i][j]);
	while(TT--){
		B.clear(); W.clear();
		int K; scanf("%d", &K);
		for(int i=1, a ,b, c; i<=K; i++){
			scanf("%d%d%d", &b, &a, &c);
			if(c == 1)
				B.push_back(make_pair(a, b));
			else
				W.push_back(make_pair(a, b));
		}
		if(B.empty() || W.empty()){
			printf("0\n");
			continue;
		}
		Dinic::init();
		S = Dinic::newS(); T = Dinic::newT();
		for(int i=1; i<=N; i++)
			for(int j=1; j<=M; j++)
				ID[i][j] = Dinic::newN();
		for(int i=1; i<N; i++)
			for(int j=1; j<=M; j++){
				Dinic::addEs(ID[i][j], ID[i+1][j], dis1[i][j]);
				Dinic::addEs(ID[i+1][j], ID[i][j], dis1[i][j]);
			}
		for(int i=1; i<=N; i++)
			for(int j=1; j<M; j++){
				Dinic::addEs(ID[i][j], ID[i][j+1], dis2[i][j]);
				Dinic::addEs(ID[i][j+1], ID[i][j], dis2[i][j]);
			}
		for(int i=0; i<(int)B.size(); i++){
			int q = Dinic::newN();
			Dinic::addEs(S, q, 1e9);
			Dinic::addEs(q, getLnk(B[i].first), B[i].second);
		}
		for(int i=0; i<(int)W.size(); i++){
			int q = Dinic::newN();
			Dinic::addEs(q, T, 1e9);
			Dinic::addEs(getLnk(W[i].first), q, W[i].second);
		}
		printf("%lld\n", Dinic::calcAns());
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
